﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//Please add references
namespace TierApplication
{
	/// <summary>
	/// 类T_PRODUCTITEM。
	/// </summary>
    public partial class T_PRODUCTITEM
    {
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetProductItemListByImpBatchNo(string sBatchNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select PRODUCTITEMID,CARDNO,CARDPWD,PRODUCTITEMSTATUS, ");
            strSql.Append("(Select CodeName from C_ProductItemStatus where CodeID=a.PRODUCTITEMSTATUS) PRDUCTITEMSTATUSNAME, ");
            strSql.Append("(Select IMPDATE from T_PRODUCTIMP where IMPBATCHNO=a.IMPBATCHNO) CRATEDATE ");
            strSql.Append(" FROM T_PRODUCTITEM a ");
            strSql.Append(" where IMPBatchNo ='" + sBatchNo+"'");
            return DbHelperOra.Query(strSql.ToString());
        }
        //充值卡礼拜
        public DataSet SP_GET_CARDLIST(string ac_where)
        {
            OracleParameter[] parameters =  {
                new OracleParameter("ac_where",OracleType.VarChar,4000),
                new OracleParameter("REFCURSOR",OracleType.Cursor)
                                            };
            parameters[0].Value = ac_where;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[1].Direction = ParameterDirection.Output;

            DataSet ds = DbHelperOra.RunProcedure("SP_GET_CARDLIST", parameters, "CardList");
            return ds;
        
        }

        //充值卡库存：包括待审核、代售、待付款
        public DataSet SP_GET_CARD_STOCK(string ac_where)
        {
            OracleParameter[] parameters =  {
                new OracleParameter("ac_where",OracleType.VarChar,4000),
                new OracleParameter("REFCURSOR",OracleType.Cursor)
                                            };
            parameters[0].Value = ac_where;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[1].Direction = ParameterDirection.Output;

            DataSet ds = DbHelperOra.RunProcedure("SP_GET_CARD_STOCK", parameters, "CardList");
            return ds;

        }

        //充值卡已售卡统计
        public DataSet SP_GET_CARD_SELL_RPT(string ac_where)
        {
            OracleParameter[] parameters =  {
                new OracleParameter("ac_where",OracleType.VarChar,4000),
                new OracleParameter("REFCURSOR",OracleType.Cursor)
                                            };
            parameters[0].Value = ac_where;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[1].Direction = ParameterDirection.Output;

            DataSet ds = DbHelperOra.RunProcedure("SP_GET_CARD_SELL_RPT", parameters, "CardList");
            return ds;

        }

        /// <summary>
        /// 取得商品数量
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public int GetProductCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select count(*)  ");
            strSql.Append(" FROM t_productitem ");
            strSql.Append(" where 1=1" + strWhere);
            DataSet ds = DbHelperOra.Query(strSql.ToString());
            if (ds != null && ds.Tables.Count != 0 && ds.Tables[0].Rows.Count != 0)
            {
                return Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            }
            else
            {
                return 0;
            }
        }
    }
}

